package org.me.Anime;

import java.util.ArrayList;
import java.util.List;

import org.me.Anime.Utli.FileUtli;
import org.me.Anime.Utli.GlobalVariable;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class DrawAnimeActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
	private DrawAnimeView mDrawImageView;
	
	private static List<Path> mPaths = new ArrayList<Path>();
	private static Bitmap mBitmap;
	
	Context mContext;
	
	//function
	
	ImageView imgDraw;
	ImageView imgPaint;
	ImageView imgClear;
	ImageView imgPickColor;
	ImageView imgPickImage;
	ImageView imgOpen;
	
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mContext = this;
        imgDraw = (ImageView)findViewById(R.id.imgDraw);
        imgPaint = (ImageView)findViewById(R.id.imgPaint);
        imgClear = (ImageView)findViewById(R.id.imgClear);
        imgPickColor = (ImageView)findViewById(R.id.imgPickColor);
        imgPickImage = (ImageView)findViewById(R.id.imgPickImage);
        imgOpen = (ImageView)findViewById(R.id.imgOpen);
        
        GlobalVariable.listImg = FileUtli.GetImageFromAssets(mContext, "image");
        
        imgDraw.setOnClickListener(this);
        imgPaint.setOnClickListener(this);
        imgClear.setOnClickListener(this);
        imgPickColor.setOnClickListener(this);
        imgPickImage.setOnClickListener(this);
        imgOpen.setOnClickListener(this);
        GlobalVariable.checkResume = true;
        
        
        mDrawImageView = (DrawAnimeView)findViewById(R.id.viewAss);
        mDrawImageView.setPaths(mPaths);
        mDrawImageView.setBitmap(mBitmap);
    }
    @Override
    protected void onPause() {
    	// TODO Auto-generated method stub
    	super.onPause();
    	GlobalVariable.checkResume = false;
    }
	   
	   @Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if(!GlobalVariable.checkResume)
		{
			if(!GlobalVariable.checkPickColor)
			{
				//mPaths.clear(); 
				//onCreate(null);
			}
		}
	}

	@Override
	public void onClick(View v) {
		
		switch(v.getId())
		{
			case R.id.imgDraw:
				GlobalVariable.IsDraw = true;
				break;
			case R.id.imgPaint:
				GlobalVariable.IsDraw = false;
				break;
			case R.id.imgClear:
				GlobalVariable.isDelete = true;
				if(mBitmap!=null){
					mBitmap.recycle();
					mBitmap = null;
				}
				
				mPaths.clear(); 
				mDrawImageView.setBitmap(null);
				break;
			case R.id.imgPickColor:
				Intent intent = new Intent(mContext, DrawAnimeColorActivity.class);
				startActivity(intent);
                break;
			case R.id.imgPickImage:
				GlobalVariable.isDelete = false;
				Intent intentPickimage = new Intent(mContext, DrawAnimeImageActivity.class);
				startActivity(intentPickimage);
				break;
			case R.id.imgOpen:
				Intent intentOpen = new Intent();
				intentOpen.setAction(Intent.ACTION_GET_CONTENT);
				intentOpen.setType("image/png");
				startActivityForResult(intentOpen, GlobalVariable.ACTION_LOAD_IMAGE);
				break;

		}
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		mPaths.clear(); 
		System.gc();
	}
	
	
}